package shopping;

// 导入ArrayList和List类对购物车的元素进行管理
import java.util.ArrayList;
import java.util.List;
// 导入Scanner类
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        // 初始化商品
        List<Item> items = new ArrayList<>();
        items.add(new Item("雪碧", "饮料", 3.0, 20));
        items.add(new Item("可乐", "饮料", 3.5, 15));
        items.add(new Item("果汁", "饮料", 5.0, 10));
        items.add(new Item("苹果", "水果", 2.0, 30));
        items.add(new Item("香蕉", "水果", 1.5, 25));
        items.add(new Item("橙子", "水果", 2.5, 20));
        items.add(new Item("洗发水", "洗护", 25.0, 10));
        items.add(new Item("沐浴露", "洗护", 20.0, 15));
        items.add(new Item("牙膏", "洗护", 15.0, 20));
        items.add(new Item("卫生纸", "生活用品", 10.0, 30));
        items.add(new Item("洗衣液", "生活用品", 15.0, 25));
        items.add(new Item("洗手液", "生活用品", 12.0, 20));
        items.add(new Item("猪肉", "肉类", 20.0, 10));
        items.add(new Item("鸡肉", "肉类", 15.0, 15));
        items.add(new Item("牛肉", "肉类", 25.0, 20));

        // 初始化购物车，设置容量为5
        Cart cart = new Cart(5);

        Scanner scanner = new Scanner(System.in);
        while (true) {
            System.out.println("\nWELCOME TO THE SHOPPING SYSTEM!");
            System.out.println("\n==== 购物系统 ====");
            System.out.println("1. 查看商品列表");
            System.out.println("2. 添加商品到购物车");
            System.out.println("3. 查看购物车");
            System.out.println("4. 移除购物车商品");
            System.out.println("5. 结算");
            System.out.println("6. 退出系统");
            System.out.print("请选择操作：");
            int choice = scanner.nextInt();

            switch (choice) {
                case 1:
                    System.out.println("商品列表：");
                    for (int i = 0; i < items.size(); i++) {
                        Item item = items.get(i);
                        System.out.println(item);
                    }
                    break;

                case 2:
                    System.out.print("请输入要添加的商品名称：");
                    String addItemName = scanner.next();
                    System.out.print("请输入添加的数量：");
                    int addItemQuantity = scanner.nextInt();
                    boolean found = false;
                    for (int i = 0; i < items.size(); i++) {
                        Item item = items.get(i);
                        if (item.getName().equals(addItemName)) {
                            cart.addItemToCart(item, addItemQuantity);
                            found = true;
                            break;
                        }
                    }
                    if (!found) {
                        System.out.println("未找到该商品！");
                    }
                    break;

                case 3:
                    cart.viewCart();
                    break;

                case 4:
                    System.out.print("请输入要移除的商品名称：");
                    String removeItemName = scanner.next();
                    cart.removeItemFromCart(removeItemName);
                    break;

                case 5:
                    cart.checkout();
                    break;

                case 6:
                    System.out.println("感谢使用购物系统，再见！");
                    scanner.close();
                    return;

                default:
                    System.out.println("无效操作，请重新选择！");
            }
        }
    }
}
